package com.yang.springcloud.controller;

import com.yang.springcloud.pojo.Member;
import com.yang.springcloud.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

@RestController
public class MemberConsumerConterller {
    @Autowired
    private RestTemplate rte;

    private static final String REST_URL_PREFIX = "http://SPRINGCLOUD-PROVIDER-MEMBER";

    @PostMapping("/consumer/member/insert")
    public Map<String, Object> addMember(@RequestParam(name = "name") String name, @RequestParam(name = "info") String info){
        System.out.println(name);
        return rte.postForObject(REST_URL_PREFIX+"/insertInfo", info, Map.class);
    }

    @GetMapping("/consumer/member/query")
    public List<Member> queryMember(){
        return rte.getForObject(REST_URL_PREFIX+"/queryAll", List.class);

    }

    @GetMapping("/consumer/member/queryById/{passid}")
    public Student queryById(@PathVariable("passid") String passid){

        return rte.getForObject(REST_URL_PREFIX+"/queryById/"+passid, Student.class);
    }
}
